// src/main/java/org/zachary/creditbusiness/hotel/controller/HotelController.java
package org.zachary.creditbusiness.hotel.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zachary.creditbusiness.hotel.controller.dto.HotelFilterCriteria;
import org.zachary.creditbusiness.hotel.controller.dto.HotelNameSearchDTO;
import org.zachary.creditbusiness.hotel.entity.Hotel;
import org.zachary.creditbusiness.hotel.exception.BusinessException;
import org.zachary.creditbusiness.hotel.service.HotelService;

import java.util.List;

@Api(tags = "酒店模块")
@RestController
@RequestMapping("/hotels")
public class HotelController {

    private final HotelService hotelService;

    @Autowired
    public HotelController(HotelService hotelService) {
        this.hotelService = hotelService;
    }

    @ApiOperation("【筛选】酒店列表（最低评分、位置、价格区间）")
    @GetMapping("/filter")
    public List<Hotel> filterHotels(HotelFilterCriteria criteria) {
        return hotelService.filterHotels(criteria);
    }

    @ApiOperation("【名称搜索】酒店列表（精确匹配名称）")
    @GetMapping("/search")
    public List<Hotel> searchByName(@ModelAttribute HotelNameSearchDTO dto) {
        return hotelService.findHotelsByName(dto.getName());
    }

    @ApiOperation("获取酒店详情（根据 ID）")
    @GetMapping("/{hotelId}")
    public Hotel getHotelById(@PathVariable("hotelId") Integer hotelId) {
        Hotel hotel = hotelService.getById(hotelId);
        if (hotel == null) {
            throw new BusinessException("酒店不存在，ID=" + hotelId);
        }
        return hotel;
    }

}